package indi.defoliation.unknownrpg.api.lore.loretable;

import org.bukkit.inventory.ItemStack;

import team.unstudio.udpl.item.ItemWrapper;

public interface LoreHelper {
	static ItemStack addLoreTable(ItemStack item, LoreTable... table) {
		ItemWrapper wrapper = new ItemWrapper(item);
		for(LoreTable t : table) {
			wrapper.addLore(t.getLore(item).toArray(new String[0]));
		}
		return wrapper.get();
	}
	static ItemStack updateLoreTable(ItemStack item, LoreTable... table) {
		ItemWrapper wrapper = new ItemWrapper(removeItemLoreText(item,table));
		for(LoreTable t : table) {
			int head = t.getHead(item);
			if(head==-1)continue;
			wrapper.addLore(head, t.getLore(item).toArray(new String[0]));
		}
		return wrapper.get();
	}
	static ItemStack removeLoreTable(ItemStack item, LoreTable... table) {
		for(LoreTable t : table) {
			item = t.removeLore(item);
		}
		return item;
	}
	
    static ItemStack removeItemLoreText(ItemStack item,LoreTable... table) {
    	ItemWrapper wrapper = new ItemWrapper(item);
    	for(LoreTable t:table) {
    		int head = t.getHead(item);
			if(head==-1)continue;
			int length = t.getLength(item);
    		for(int i = head;i<length;i++) {
				wrapper.removeLore(i);
			}
    	}
    	return wrapper.get();
	}
	static boolean hasLoreTable(ItemStack item, LoreTable table) {
		return table.getHead(item)!=-1;
	}
}